home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / fax / src / faxd / HDLCFrame.h < prev    next >
C/C++ Source or Header  |  1994-08-01  |  4KB  |  85 lines

  1. /*    $Header: /usr/people/sam/fax/faxd/RCS/HDLCFrame.h,v 1.10 1994/02/28 14:14:38 sam Rel $ */
  2. /*
  3.  * Copyright (c) 1990, 1991, 1992, 1993, 1994 Sam Leffler
  4.  * Copyright (c) 1991, 1992, 1993, 1994 Silicon Graphics, Inc.
  5.  *
  6.  * Permission to use, copy, modify, distribute, and sell this software and 
  7.  * its documentation for any purpose is hereby granted without fee, provided
  8.  * that (i) the above copyright notices and this permission notice appear in
  9.  * all copies of the software and related documentation, and (ii) the names of
  10.  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  11.  * publicity relating to the software without the specific, prior written
  12.  * permission of Sam Leffler and Silicon Graphics.
  13.  * 
  14.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  15.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  16.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  17.  * 
  18.  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  19.  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  20.  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  21.  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
  22.  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
  23.  * OF THIS SOFTWARE.
  24.  */
  25. #ifndef _HDLCFRAME_
  26. #define    _HDLCFRAME_
  27. /*
  28.  * Raw HDLC Frame Interface.
  29.  */
  30. #include "Types.h"
  31.  
  32. class HDLCFrame {
  33. public:
  34.     HDLCFrame(u_int frameOverhead);
  35.     HDLCFrame(const HDLCFrame& fr);
  36.     ~HDLCFrame();
  37.  
  38.     void put(u_char c);            // Put the character "c" into the buffer
  39.     void put(const u_char* c, u_int len);// Put bunch of bytes in the buffer
  40.     void reset();            // Reset buffer to empty
  41.     u_int getLength() const;        // Return number of bytes in buffer
  42.  
  43.     operator u_char*();            // Return base of buffer
  44.     u_char& operator[](u_int i) const;    // NB: no bounds checking
  45.  
  46.     fxBool moreFrames() const;        // more frames follow
  47.     fxBool isOK() const;        // frame has good FCS
  48.     void setOK(fxBool b);        // set frame FCS indicator
  49.     u_int getFCF() const;        // FCF in frame
  50.     const u_char* getFrameData() const;    // data following FCF
  51.     u_int getFrameDataLength() const;    // length of data - (FCF+FCS)
  52.     u_int getDataWord() const;        // first 0-4 bytes of data
  53.     u_int getDIS() const;        // DIS/DCS data
  54.     u_int getXINFO() const;        // extended info after DIS/DCS
  55. protected:
  56.     u_char    buf[2048];        // large enough for TCF at 9600 baud
  57.     u_char*    next;
  58.     u_char*    end;
  59.     u_char*    base;
  60.     u_short    amountToGrowBy;
  61.     u_short    frameOverhead;        // # bytes for leader & FCS
  62.     fxBool    ok;            // FCS correct
  63.  
  64.     void addc(u_char c);        // make room & add a char to the buffer
  65.     void grow(u_int amount);        // make more room in the buffer
  66. };
  67.  
  68. inline void HDLCFrame::put(u_char c)
  69.     { if (next < end) *next++ = c; else addc(c); }
  70. inline void HDLCFrame::reset()                { next = base; ok = FALSE; }
  71. inline u_int HDLCFrame::getLength() const        { return next - base; }
  72.  
  73. inline HDLCFrame::operator u_char*()            { return base; }
  74. inline u_char& HDLCFrame::operator[](u_int i) const { return base[i]; }
  75.  
  76. inline fxBool HDLCFrame::moreFrames() const
  77.     { return ((*this)[1]&0x08) == 0; }
  78. inline fxBool HDLCFrame::isOK() const             { return ok; }
  79. inline void HDLCFrame::setOK(fxBool b)             { ok = b; }
  80. inline u_int HDLCFrame::getFCF() const             { return (*this)[2]; }
  81. inline const u_char* HDLCFrame::getFrameData() const { return &((*this)[3]); }
  82. inline u_int HDLCFrame::getFrameDataLength() const
  83.     { return getLength() - frameOverhead; }
  84. #endif /* _HDLCFRAME_ */
  85.